package com.xiaobai.netease_news.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Android Studio
 * Project: NeteaseNews
 * Author: Jack
 * Email: jackfangqi1314@gmail.com/jackfangqi@163.com
 * Date: 2015/6/4
 */
public class ResponseData {
    private String template;
    private boolean hasCover;
    private int hasHead;
    private String skipId;
    private int replyCount;
    private String alias;
    private int hasImg;
    private String digest;
    private boolean hasIcon;
    private String skipType;
    private String cid;
    private String docid;
    private String title;
    private int hasAD;
    private int order;
    private List<ImgExtra> imgExtras;
    private int priority;
    private String lmodify;
    private String ename;
    private String tname;
    private String imgsrc;
    private String photosetId;
    private String ptime;
    private String url_3w;
    private String url;
    private String tags;
    private String source;
    private String subtitle;
    private String boardid;
    private String tag;
    private String specialId;
    private List<Editor> editors;
    private int votecount;
    private int imgType;

    public String getTemplate() {
        return template;
    }

    public boolean isHasCover() {
        return hasCover;
    }

    public int getHasHead() {
        return hasHead;
    }

    public String getSkipId() {
        return skipId;
    }

    public int getReplyCount() {
        return replyCount;
    }

    public String getAlias() {
        return alias;
    }

    public int getHasImg() {
        return hasImg;
    }

    public String getDigest() {
        return digest;
    }

    public boolean isHasIcon() {
        return hasIcon;
    }

    public String getSkipType() {
        return skipType;
    }

    public String getCid() {
        return cid;
    }

    public String getDocid() {
        return docid;
    }

    public String getTitle() {
        return title;
    }

    public int getHasAD() {
        return hasAD;
    }

    public int getOrder() {
        return order;
    }

    public List<ImgExtra> getImgExtras() {
        return imgExtras;
    }

    public int getPriority() {
        return priority;
    }

    public String getLmodify() {
        return lmodify;
    }

    public String getEname() {
        return ename;
    }

    public String getTname() {
        return tname;
    }

    public String getImgsrc() {
        return imgsrc;
    }

    public String getPhotosetId() {
        return photosetId;
    }

    public String getPtime() {
        return ptime;
    }

    public String getUrl_3w() {
        return url_3w;
    }

    public String getUrl() {
        return url;
    }

    public String getTags() {
        return tags;
    }

    public String getSource() {
        return source;
    }

    public String getSubtitle() {
        return subtitle;
    }

    public String getBoardid() {
        return boardid;
    }

    public String getTag() {
        return tag;
    }

    public String getSpecialId() {
        return specialId;
    }

    public List<Editor> getEditors() {
        return editors;
    }

    public int getVotecount() {
        return votecount;
    }

    public int getImgType() {
        return imgType;
    }

    public void parseJson(JSONObject jsonObject) {
        if (jsonObject != null) {
            template = jsonObject.optString("template");
            hasCover = jsonObject.optBoolean("hasCover");
            hasHead = jsonObject.optInt("hasHead");
            skipId = jsonObject.optString("skipID");
            replyCount = jsonObject.optInt("replyCount");
            alias = jsonObject.optString("alias");
            hasImg = jsonObject.optInt("hasImg");
            digest = jsonObject.optString("digest");
            hasIcon = jsonObject.optBoolean("hasIcon");
            skipType = jsonObject.optString("skipType", "");
            cid = jsonObject.optString("cid");
            docid = jsonObject.optString("docid");
            title = jsonObject.optString("title");
            hasAD = jsonObject.optInt("hasAD");
            order = jsonObject.optInt("order");
            priority = jsonObject.optInt("priority");
            lmodify = jsonObject.optString("lmodify");
            ename = jsonObject.optString("ename");
            tname = jsonObject.optString("tname");
            imgsrc = jsonObject.optString("imgsrc");
            photosetId = jsonObject.optString("photosetID");
            ptime = jsonObject.optString("ptime");
            url_3w = jsonObject.optString("url_3w");
            url = jsonObject.optString("url");
            tags = jsonObject.optString("TAGS", "");
            tag = jsonObject.optString("TAG", "");
            source = jsonObject.optString("source");
            subtitle = jsonObject.optString("subtitle");
            boardid = jsonObject.optString("boardid");
            specialId = jsonObject.optString("specialID");
            votecount = jsonObject.optInt("votecount");
            imgType = jsonObject.optInt("imgType", 0);

            JSONArray array = jsonObject.optJSONArray("imgextra");
            if (array != null) {
                imgExtras = new ArrayList<>();
                for (int i = 0; i < array.length(); i++) {
                    try {
                        JSONObject object = array.getJSONObject(i);
                        ImgExtra imgExtra = new ImgExtra();
                        imgExtra.parseJson(object);
                        imgExtras.add(imgExtra);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

            JSONObject object = jsonObject.optJSONObject("editor");
            if (object != null) {
                editors = new ArrayList<>();
                Editor editor = new Editor();
                editor.parseJson(object);
                editors.add(editor);
            }
        }
    }
}
